package com.xzx.shop_front_api.controller;

import com.xzx.shop_front_api.entity.Goods;
import com.xzx.shop_front_api.service.GoodsService;
import com.xzx.shop_front_api.utils.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("api/goods")
public class GoodsController {
    @Autowired
    private StringRedisTemplate stringRedisTemplate;
    @Autowired
    private GoodsService goodsService;
    @PostMapping("add")
    public JsonResult add(@RequestBody Goods goods) {
        int result = goodsService.addGoods(goods);
        if (result == 0) {
            JsonResult.failed("添加失败");
        }
        //
        return JsonResult.success("添加成功",null);
    }

    @GetMapping("list")
    public JsonResult list(@RequestParam("cate_id") int cateId ,
                           @RequestParam("level") int level) {
        List<Goods> goodsList = goodsService.getGoodsByCateId(cateId, level);
        return JsonResult.success("获取成功",goodsList);
    }
}
